from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey, UniqueConstraint, Index
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy import create_engine
from mogu_models import *

# 创建数据库连接
engine = create_engine("mysql+pymysql://root:123456@127.0.0.1:3306/mogujie?charset=utf8", max_overflow=5,encoding='utf-8')
session_maker = sessionmaker(bind=engine)
# 创建数据库会话
session = session_maker()

# 保存商品数据

def save_goods(item):
    goods = Goods()
    goods.trade_item_id = item['tradeItemId']
    goods.title = item['title']
    goods.category = item['category']
    goods.link = item['link']
    goods.org_price = item['orgPrice']
    goods.price = item['price']
    goods.sale = item['sale']
    session.add(goods)
    session.commit()



